package net.juantxu.pentaho.launcher.utilidades;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import org.apache.log4j.Logger;

public class CopiaArchivos{
	static Logger log = Logger.getLogger(CopiaArchivos.class);
	
  public  CopiaArchivos(String srFile, String dtFile){
    try{
      File f1 = new File(srFile);
      File f2 = new File(dtFile);
      InputStream in = new FileInputStream(f1);
      
      //For Append the file.
//      OutputStream out = new FileOutputStream(f2,true);

      //For Overwrite the file.
      OutputStream out = new FileOutputStream(f2);

      byte[] buf = new byte[1024];
      int len;
      while ((len = in.read(buf)) > 0){
        out.write(buf, 0, len);
      }
      in.close();
      out.close();
      log.debug("archivo copiado" + srFile + "a" + dtFile);

    }
    catch(FileNotFoundException ex){
        log.error(ex.getMessage() + " in the specified directory.");

    }
    catch(IOException e){
    	 log.error(e.getMessage());
   
    }
  }
 
}